import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 请求相应的封装
 */
public class Response {
    public Response(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    private OutputStream outputStream;

    public OutputStream getOutputStream() {
        return outputStream;
    }

    public void setOutputStream(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    /**
     * 相应html
     * @param path
     * @throws IOException
     */
    public void  outputHtml(String path) throws IOException {
        String absResourcePath=StaticResourceUtil.getAbsolutePath(path);
        File file = new File(absResourcePath);
        if(file.exists() && file.isFile()){
                StaticResourceUtil.outputStaticResource(new FileInputStream(file),outputStream);
        }else {
            output(HttpProcotoUtil.getHeader404());
        }
    }

    public void  output(String content) throws IOException {
        outputStream.write(content.getBytes());
    }
}


